<?php
namespace Home\Controller;
use Home\Controller\HomeController;

class ErpController extends HomeController {
    //空操作
    public function _initialize(){
        parent::_initialize();
    }
    public function _empty(){
        header("HTTP/1.0 404 Not Found");
        $this->display('Public:404');
    }
    public function index(){
    	$orders = M('Orders')->where(array('member_id'=>$_SESSION['USER_KEY_ID']))->select();
		foreach($orders as $k=>$v){
			if(empty($orders[$k]['wl'])){
				$url = "http://218.4.45.147:6666/PDAService.asmx?wsdl";
				$client=new \SoapClient($url);
				$ret = $client->getJufineWljson(array('vbillno'=>$orders[$k]['vdef3']));
				//对象转数组
				$array  =  json_decode( json_encode( $ret),true);
				$json = $array['getJufineWljsonResult'];
				//json转换成数组
				$aa = json_decode($json,true);
					
				$orders[$k]['wl'] = $aa['wl']['expressno'];
				//查询一次写入数据库
				if($aa){
					$data['wl'] = $orders[$k]['wl'];
					$re[] = M('Orders')->where(array('order_id'=>$orders[$k]['order_id']))->save($data);
				}
			}
			$good = M('Goods')->where(array('id'=>$orders[$k]['goods_id']))->find();
			$orders[$k]['good_name'] = $good['gname'];
		}
// 		dump($orders);
// 		die();
		$this->assign('orders',$orders);
    	$this->display();
    }




	
	
	/**
	 * 物流信息
	 */
	public function logistics(){
		
		$djbh = 'TH20170703000028';
		$url = "http://218.4.45.147:6666/PDAService.asmx?wsdl";
		$client=new \SoapClient($url);
		$ret = $client->getJufineWljson(array('vbillno'=>$djbh));
		//对象转数组
		$array  =  json_decode( json_encode( $ret),true);
		$json = $array['getJufineWljsonResult'];
		//json转换成数组
		$aa = json_decode($json,true);
// 		dump($aa);
// 		die();
		$this->assign('wl',$aa['wl']);
		$this->display();
	}




	
}